﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace Hrm.Core.Mvc
{
    public static class HrmHtmlHelper
    {
        /// <summary>
        /// <div class="form-group">
        /// <label class="col-lg-2 col-md-3 control-label" for="">Default input</label>
        /// <div class="col-lg-10 col-md-9">
        /// <input type="text" class="form-control" name="default">
        /// </div>
        /// </summary>
        /// <param name="htmlHelper"></param>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <param name="format"></param>
        /// <param name="htmlAttributes"></param>
        /// <returns></returns>
        public static MvcHtmlString LabelAndTextBox(this HtmlHelper htmlHelper, string name, object labelValue,
            object htmlAttributes)
        {
            TagBuilder divTag=new TagBuilder("div");
            divTag.AddCssClass("form-group");
            var htmlAttributess=HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
            if (htmlAttributess.Keys.Contains("class"))
            {
                divTag.AddCssClass(htmlAttributess["class"].ToString());
                htmlAttributess.Remove("class");
            }
            divTag.MergeAttributes<string, object>(htmlAttributess);
            TagBuilder labelTag = new TagBuilder("label");
            labelTag.AddCssClass("col-lg-2 col-md-3 control-label");
            labelTag.MergeAttribute("for",name);
            labelTag.SetInnerText(labelValue.ToString());
            TagBuilder innerDivTag = new TagBuilder("div");
            innerDivTag.AddCssClass("col-lg-10 col-md-9");
            TagBuilder textTag = new TagBuilder("input");
            textTag.AddCssClass("form-control");
            textTag.MergeAttribute("type","text");
            textTag.MergeAttribute("id", name);
            textTag.MergeAttribute("name", name);
            innerDivTag.InnerHtml = textTag.ToString();
            divTag.InnerHtml = labelTag.ToString() + innerDivTag.ToString();
            return new MvcHtmlString(divTag.ToString(TagRenderMode.Normal));
        }
    }
}
